// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: V Block Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 53 : TYPE_VBLOCK

// Function declarations
reserve function VBlock_DebugDraw
reserve function VBlock_DebugSpawn

// Static Values
private value value0xF33E = 0;

// Tables

function VBlock_DebugDraw
	DrawSprite(0)
end function


function VBlock_DebugSpawn
	CreateTempObject(TypeName[V Block], object.direction, object.xpos, object.ypos)
	if object[tempObjectPos].propertyValue == 1
		object[tempObjectPos].ypos -= 0x200000
	else
		object[tempObjectPos].ypos -= 0x1F0000
	end if
end function


event ObjectMain
	object.angle = SYZSetup_value29
	object.angle *= 512
	object.angle /= 356
	if object.propertyValue == 1
		object.angle += 256
	end if
	object.angle &= 511
	Sin(object.value2, object.angle)
	object.value2 <<= 12
	object.value2 += object.ypos
	object.value2 &= -0x10000
	object.value2 -= object.value1
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		temp0 = object.ypos
		object.ypos = object.value1
		CheckEqual(object[currentPlayer].state, PlayerObject_HandleMonikaTeleport)
		temp2 = checkResult
		CheckLower(object[0].value1, 20)
		temp2 &= checkResult
		if temp2 == 0			
			BoxCollisionTest(C_BOX, object.entityPos, -32, -32, 32, 32, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			switch checkResult
			case 1
				object[currentPlayer].ypos += object.value2
				break
			case 4
				if object[currentPlayer].gravity == GRAVITY_GROUND
					if object.angle > 384
						CallFunction(PlayerObject_Kill)
					end if
					if object.angle < 128
						CallFunction(PlayerObject_Kill)
					end if
				end if
				break
			end switch
		end if
		if object[currentPlayer].state == PlayerObject_HandleMonikaTeleport
			if object[0].value1 >= 14
				BoxCollisionTest(C_TOUCH, object.entityPos, -32, -32, 32, 32, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
				if checkResult == 1
					if object[currentPlayer].ypos > object.ypos
						object[currentPlayer].iypos = object[currentPlayer].collisionBottom
						FlipSign(object[currentPlayer].ypos)
						object[currentPlayer].ypos += 0x400000
						object[currentPlayer].ypos += object.ypos
						if object[currentPlayer].yvel < 0
							object[currentPlayer].yvel = 0
						end if
					else
						object[currentPlayer].iypos = object[currentPlayer].collisionTop
						FlipSign(object[currentPlayer].ypos)
						object[currentPlayer].ypos -= 0x400000
						object[currentPlayer].ypos += object.ypos
						if object[currentPlayer].yvel > 0
							object[currentPlayer].yvel = 0
						end if
					end if		
				end if	
			end if	
		end if	
		object.ypos = temp0
	next
end event


event ObjectDraw
	Sin(object.value1, object.angle)
	object.value1 <<= 12
	object.value1 += object.ypos
	object.value1 &= -0x10000
	DrawSpriteXY(0, object.xpos, object.value1)
end event


event ObjectStartup
	LoadSpriteSheet("SYZ/Objects.gif")
	SpriteFrame(-32, -32, 64, 64, 119, 34)
	foreach (TypeName[V Block], arrayPos0, ALL_ENTITIES)
		if object[arrayPos0].propertyValue == 1
			object[arrayPos0].ypos -= 0x200000
		else
			object[arrayPos0].ypos -= 0x1F0000
		end if
	next
	SetTableValue(TypeName[V Block], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(VBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(VBlock_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
